package com.rmt.www.action;




import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.rmt.www.service.LogonService;
import com.rmt.www.vo.User;


public class LoginAction extends ActionSupport{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private String username;
	private String password;
	private LogonService logonService;
	
	
	public LogonService getLogonService() {
		return logonService;
	}
	public void setLogonService(LogonService logonService) {
		this.logonService = logonService;
	}
	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public String execute(){
		String[] logonResult = logonService.logonResult(username, password);
		if(logonResult[0].equalsIgnoreCase("noaccount") || logonResult[0].equalsIgnoreCase("invalidpassword")){
			this.addFieldError("loginFailed", logonResult[1]);
			return "fail";
		} else {
			return logonResult[0];	//admin or others
		}
	}
	
}
